//
//  LeftOneRightTwoImageCell.m
//  Product_NEWS
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 FCH. All rights reserved.
//

//左一
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height )

#define leftImage_W WIDTH * 3  / 5 - 10 * SCREEN_WIDTH
#define leftImage_H HEIGHT / 3

//右上
#define rightImageUp_X leftImage_W + 3 * SCREEN_WIDTH
#define rightImageUp_W leftImage_W / 2
#define rightImageUp_H leftImage_H / 2 - 1 *SCREEN_HEIGHT

//右下
#define  rightImageDown_X rightImageUp_X

#define  rightImageDown_Y rightImageUp_H + 3 *SCREEN_HEIGHT

#define  rightImageDown_W rightImageUp_W

#define  rightImageDown_H (leftImage_H - rightImageUp_H)


//标题

#define titleLabel_X 10* SCREEN_WIDTH
#define titleLabel_Y leftImage_H + 10 * SCREEN_HEIGHT
#define titleLabel_W WIDTH  -titleLabel_X - 20 *SCREEN_WIDTH
#define titleLabel_H 30 * SCREEN_HEIGHT


#import "LeftOneRightTwoImageCell.h"
#import "UIImageView+WebCache.h"


@interface LeftOneRightTwoImageCell ()

@property (nonatomic, retain) UIImageView *leftImage; //左单一的一个图
@property (nonatomic, retain) UILabel *titleLabel;  //标题

@property (nonatomic, retain) UILabel *sourceLabel;  //左下角来源
@property (nonatomic, retain) UIImageView *rightImageUp;  //右上图片
@property (nonatomic, retain) UIImageView *rightImageDown;  //右下图片
@property(nonatomic,retain)UIView *lineView; //横线
@end

@implementation LeftOneRightTwoImageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
        
    }
    return self;
}

-(void)createSubviews{
    self.leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, leftImage_W, leftImage_H)];
    
    [self.contentView addSubview:self.leftImage];
    [_leftImage release];
    
    self.rightImageUp = [[UIImageView alloc]initWithFrame:CGRectMake(rightImageUp_X, 0, rightImageUp_W, rightImageUp_H)];
    
    [self.contentView addSubview:self.rightImageUp];
    [_rightImageUp release];
    
    
    self.rightImageDown = [[UIImageView alloc]initWithFrame:CGRectMake(rightImageDown_X, rightImageDown_Y, rightImageDown_W, rightImageDown_H)];
    [self.contentView addSubview:self.rightImageDown];
    [_rightImageDown release];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabel_X, titleLabel_Y, titleLabel_W, titleLabel_H)];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(titleLabel_X, titleLabel_Y + 30 *SCREEN_HEIGHT, WIDTH - 2 * titleLabel_X - 20 * SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.lineView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.000];
    [self.contentView addSubview:self.lineView];
    [_lineView release];
    
    self.sourceLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabel_X, titleLabel_Y + 40 * SCREEN_HEIGHT, 120 * SCREEN_WIDTH, 20 * SCREEN_HEIGHT)];
    self.sourceLabel.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    
    self.sourceLabel.font = [UIFont systemFontOfSize:13];
    
    [self.contentView addSubview:self.sourceLabel];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, self.sourceLabel.frame.origin.y + 40, WIDTH, 30)];
    [self.contentView addSubview:view];
    view.backgroundColor = [UIColor colorWithWhite:0.945 alpha:1.000];
    
}

-(void)setModel:(ReadListModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.leftImage sd_setImageWithURL:[NSURL URLWithString:model.imgsrc] placeholderImage:[UIImage imageNamed:@"contentview_imagebg_logo@2x"]];
    
    if (model.imgnewextra.count > 0 ) {
        [self.rightImageUp sd_setImageWithURL:[NSURL URLWithString:model.imgnewextra[0][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"contentview_imagebg_logo@2x"]];
        [self.rightImageDown sd_setImageWithURL:[NSURL URLWithString:model.imgnewextra[1][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"contentview_imagebg_logo@2x"]];
    }
    
    self.titleLabel.text = model.title;
    self.sourceLabel.text = model.source;
    
}

+ (CGFloat)heightForRowWithReadNews:(ReadListModel *)model {

    return leftImage_H + 120;
}



- (void)dealloc {
    [_rightImageDown release];
    [_rightImageUp release];
    [_leftImage release];
    [_lineView release];
    [_titleLabel release];
    [_sourceLabel release];
    [super dealloc];
}






@end
